package com.wwwc.index.web.servlet;

import java.io.*;
import java.awt.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.ServletRequestWrapper;
import java.net.*;
import com.wwwc.util.web.*;
import com.wwwc.index.web.ejb.database.*;
import com.wwwc.index.web.ejb.*;

public class ShoppingServlet extends HttpServlet {
    private EJBDatabaseQuery ejbdb;

    public void doGet(HttpServletRequest request, HttpServletResponse response)
    {
	doPost(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
    {	
	try {
	    response.setContentType("text/html");
	    HttpSession session  = request.getSession(true);
	    PrintWriter out      = response.getWriter();
	    String  user_ip      = request.getRemoteAddr();

	    String sid        = request.getParameter("sid");
	    String sub_dir    =  request.getParameter("sub_dir");
	    String table_name =  request.getParameter("table_name");

	    if(sid == null || sub_dir==null || table_name == null) {
		return;
	    }

	    //////////////////////////////////////////////////////////////////
	    // System propperties
	    //////////////////////////////////////////////////////////////////

	    ResourceBundle SystemInfo = (ResourceBundle)session.getAttribute("SystemInfo");
	    if (SystemInfo == null) {
		Locale locale = request.getLocale();
		SystemInfo = ResourceBundle.getBundle("SystemInfo", locale); 
		session.setAttribute("SystemInfo", SystemInfo);
	    }

	    String local_ips = SystemInfo.getString("3wcenter.local_ips");
	    String database  = SystemInfo.getString("3wcenter.database");

	    String max_rows  = SystemInfo.getString("3wcenter.content.max_rows");
	    String post_home = SystemInfo.getString("3wcenter.default.post.home");

	    ////////////////////////////////////////////////////////////////////
	    // sub-directory info
	    ////////////////////////////////////////////////////////////////////
	    Hashtable dir_hs = (Hashtable)session.getAttribute("ContralOpenClose");
	    if(dir_hs == null) {
		return;
	    }

	    int show_level   = Integer.parseInt((String)dir_hs.get(sid+"_level"));
	    int action_level = Integer.parseInt((String)dir_hs.get(sid+"_action"));
	    int action_age   = Integer.parseInt((String)dir_hs.get(sid+"_age"));
	    int post_level   = 0;

	    String tadd= (String)dir_hs.get(sid+"_post");
	    if(tadd != null && tadd.length()>0) {
		post_level = Integer.parseInt(tadd);
	    }

	    /////////////////////////////////////////////////////////////////////
	    // user info
	    ////////////////////////////////////////////////////////////////////
	    Hashtable user_info  =  (Hashtable)session.getAttribute("user_info");
	    if(user_info == null) {
		if(user_ip.startsWith(local_ips)) {
		    out.println(MyMessage.htmlMessage("ShoppingHotDeals[101]"));
		}
		return;
	    }

	    String user_name  = (String)user_info.get("user_name");
	    int user_age      = Integer.parseInt((String)user_info.get("user_age"));
	    int user_level    = Integer.parseInt((String)user_info.get("user_level"));
	    String user_fname = (String)user_info.get("user_fname");
	    String user_since = (String)user_info.get("user_since");
	    String user_edu   = (String)user_info.get("user_edu");
	    String user_zip   = (String)user_info.get("user_zip");
	    String user_sex   = (String)user_info.get("user_sex");

	    String action =  request.getParameter("aid");	   

	    //////////////////////////////////////////////////////////////////////////////
	    // show level check
	    //////////////////////////////////////////////////////////////////////////////
	    if(show_level > user_level) {
		return;
	    }

	    ////////////////////////////////////////////////////////////////////
	    // page_id == 3 (Hashtable set by IndexServlet
	    ////////////////////////////////////////////////////////////////////
	    /*
	    Hashtable pgc = (Hashtable)session.getAttribute("page_color");
	    String pc_id = "4";
	    String page_color = "<BODY>";
	    if(pgc != null) {
		page_color ="<BODY bgcolor='"+pgc.get("bgcolor_"+pc_id)+"' text='"+pgc.get("text_"+pc_id)+
		    "' link='"+pgc.get("link_"+pc_id)+"' vlink='"+pgc.get("vlink_"+pc_id)+"' alink='"+pgc.get("alink_"+pc_id)+"'>";
	    }
	    */
	    ////////////////////////////////////////////////////////////////////
	    // page head, color, ....
	    ////////////////////////////////////////////////////////////////////
	    /*
	    out.println(ContentDisplayBean.getStyleSheet(sid, 1, sub_dir));
	    out.println(page_color);
	    */

	    String pid =  request.getParameter("pid");
	    if(pid == null || !MyStringCheck.isNumber(pid)) {
		pid = "1";
	    }

	    if (ejbdb == null) {
		ejbdb = (new DatabaseEJBQuery()).getEJBDatabaseQuery();
	    }

	    String query = null;

	    if(action == null) {
		int row_counter = ejbdb.getRowCounter(table_name);
		if(row_counter == -1) {
		    if(user_ip.startsWith(local_ips) && user_level>=99) {

		    }
		    else {
			out.println(MyMessage.htmlMessage("Sorry. Please try again!"));
		    }
		    return;
		}
		/*
		query = "SELECT * FROM "+table_name+" ;";

		    cid = ejbdb.selectSingleFieldValue(query, "CATEGORY_ID");
		    if(cid == null || cid.length()<1) {
			out.println(MyMessage.htmlMessage("No product found", "Back", -1));
			return;
		    }
		}

		String page = request.getParameter("page"); 
		if(page == null) { page = "1";}

		query = "SELECT LIMIT "+(Integer.parseInt(page)-1)*Integer.parseInt(max_rows)+" "+
		    max_rows+" * FROM PRODUCTS WHERE CATEGORY_ID='"+cid+"';";

		ArrayList alist = ejbdb.select(query);

		StringBuffer sbf1 = new StringBuffer();
		sbf1.append(MyHtml.pageCounter(alist.size(), max_rows, page, "MainBarServlet?sid="+sid));
		
		StringBuffer sbf2 = new StringBuffer();
		sbf2.append("<table style='font-size: 10pt'><tr>");
		sbf2.append("<td>"+sub_dir+"</td>");
		//sbf2.append("<td>[<A href=MainBarServlet?sid="+sid+"&aid=2-1>Add Product</A>]</td>");
		sbf2.append("</tr></table>");
		

		String wid = request.getParameter("wid");

		if(wid == null) {		    
		    StringBuffer sbf3 = new StringBuffer();
		    sbf3.append("<TABLE cellSpacing=0 cellPadding=2 border=0 style='font-size: 10pt'>");
		    Iterator it  = alist.iterator();
		    ArrayList a  = null;
		    String pname = null;
		    String image = null;
		    String feature = null;
		    Hashtable rate_hs = null;
		    while (it.hasNext()) {
			a = (ArrayList)it.next();
			wid   = (String)a.get(0);
			pname = (String)a.get(1);
			image = (String)a.get(2);
			feature  = (String)a.get(8);

			sbf3.append("<TR><TD>");

			sbf3.append("<table style='font-size: 10pt' cellSpacing=5 cellPadding=5 border=0>");
			sbf3.append("<tr>");
			sbf3.append("<td  style='font-size: 10pt'>");
			sbf3.append("<A href=/servlet/MainBarServlet?sid="+sid+"&wid="+wid+">"+pname+"</A>");
			sbf3.append("</td>");
			query = "SELECT * FROM PRODUCT_PRICE WHERE WWWC_ID='"+wid+"';";
			sbf3.append("<td>$"+ejbdb.selectSingleFieldValue(query,"PRICE")+"</td>");
			query = "SELECT * FROM PRODUCT_RATING WHERE WWWC_ID='"+wid+"';";
			rate_hs = ejbdb.selectSingleRecordHashtable(query);
			sbf3.append("<td>Rating [<B>"+rate_hs.get("RATING")+"</B>] based on ("+rate_hs.get("RATERS")+") raters</td>");
			sbf3.append("<td><img src=/images/buy.gif border=0></td></tr>");
			sbf3.append("<tr><td align=left valign=top colspan=4>");
			
			if(image == null || image.length()<1) {
			    image = "/images/product_default.gif";
			}

			sbf3.append("<TABLE><TR><TD>");
			
			sbf3.append("<TABLE border=0 width=100 height=150 style=\"border: 1 solid #FFFFFF\">");
			sbf3.append("<TR><TD align=center  style=\"background-color: #FGHGFG\">");
			sbf3.append("<A href=MainBarServlet?sid="+sid+"&action=detail&wid="+wid+">");
			sbf3.append("<img src="+image+" border=0 width=90></A>");
			sbf3.append("</TD></TR></TABLE>");

			sbf3.append("</TD><TD>"+MyHtmlDisplay.textToList(feature, ";"));
			sbf3.append("</TD></TR></TABLE>");
			
			sbf3.append("</table>");
			
			sbf3.append("</TD></TR>");
		    }

		    sbf3.append("</TABLE>");
		    StringBuffer sbf = new StringBuffer();
		    sbf.append(sbf1);
		    sbf.append(sbf2);
		    sbf.append(sbf3);

		    out.println(MyHtml.forumDisplay(sid, ad_left, sbf, ad_right));
		}
		else {
		    query = "SELECT * FROM PRODUCTS WHERE ID='"+wid+"';";
		    Hashtable rh = ejbdb.selectSingleRecordHashtable(query);
		    if(rh == null) {
			return;
		    }

		    sbf2.append("<table style='font-size: 10pt' cellSpacing=0 cellPadding=0 border=0>");
		    sbf2.append("<tr>");
		    sbf2.append("<td  style='font-size: 10pt'>"+rh.get("NAME")+"</td>");
		    query = "SELECT * FROM PRODUCT_PRICE WHERE WWWC_ID='"+wid+"';";
		    sbf2.append("<td>&nbsp;&nbsp;$"+ejbdb.selectSingleFieldValue(query,"PRICE")+"</td>");
		    sbf2.append("<td><img src=/images/buy.gif border=0></td></tr>");
		    sbf2.append("</table>");

		    StringBuffer cbf = new StringBuffer();
		    String fname0 = "<A href=/servlet/MainBarServlet?sid="+sid+"&vopt=0&wid="+wid+">Detail</A>";
		    String fname1 = "<A href=/servlet/MainBarServlet?sid="+sid+"&vopt=1&wid="+wid+">Overview</A>";
		    String fname2 = "<A href=/servlet/MainBarServlet?sid="+sid+"&vopt=2&wid="+wid+">Specifications</A>";
		    String fname3 = "<A href=/servlet/MainBarServlet?sid="+sid+"&vopt=3&wid="+wid+">Features</A>";
		    String fname4 = "<A href=/servlet/MainBarServlet?sid="+sid+"&vopt=4&wid="+wid+">Package</A>";
		    String fname5 = "<A href=/servlet/MainBarServlet?sid="+sid+"&vopt=5&wid="+wid+">Images</A>";
		    String fnames[]={fname0, fname1, fname2, fname3, fname4, fname5};

		    String vopt = request.getParameter("vopt");
		    if(vopt == null)  vopt = "0";

		    if(vopt.equals("0")){
			cbf.append("<TABLE cellSpacing=0 cellPadding=10 border=0 width=600>");
			cbf.append("<TR><TD>Product:</TD><TD colspan=2><B>"+rh.get("NAME")+"</B></TD></TR>");
			cbf.append("<TR><TD>Manufacture:</TD>");
			cbf.append("<TD>"+rh.get("MANUFACTURE")+"</TD>");
			cbf.append("<TD rowspan=3><img src='"+rh.get("IMAGE")+"' onError=ImageError(this);></TD></TR>");
			cbf.append("<TR><TD>Manufacture-ID:</TD><TD>"+rh.get("SERIAL_NUMBER")+"</TD></TR>");
			cbf.append("<TR><TD>Made In:</TD><TD>"+rh.get("MADE_IN")+"</TD></TR>");
			cbf.append("</TABLE>");
		    }
		    else if(vopt.equals("1")){
			String overview = ""+rh.get("OVERVIEW");
			cbf.append("<table><tr><td>"+MyHtmlDisplay.textToHtml(overview)+"</td></tr></table>");
		    }
		    else if(vopt.equals("2")){
			String specs = ""+(String)rh.get("SPECIFICATIONS");
			if(specs.indexOf(";") != -1){
			    specs = specs.replaceAll(";","<LI></LI>");
			}
			cbf.append("<table><tr><td align=left><UL><LI>"+specs+"</LI></UL></td></tr></table>");
		    }
		    else if(vopt.equals("3")){
			String features = ""+(String)rh.get("FEATURES");
			if(features.indexOf(";") != -1){
			    features = features.replaceAll(";","<LI></LI>");
			}
			cbf.append("<table width=500><tr><td align=left><UL><LI>"+features+"</LI></UL></td></tr></table>");
		    }
		    else if(vopt.equals("4")){
			String package_include = ""+(String)rh.get("PACKAGE_INCLUDE");
			if(package_include.indexOf(";") != -1){
			    package_include = package_include.replaceAll(";","<LI></LI>");
			}
			if(package_include.length()>1){
			    cbf.append("<UL><LI>"+package_include+"</LI></UL>");
			}
		    }
		    else if(vopt.equals("5")){
			String image_links = ""+(String)rh.get("IMAGE_LINKS");
			cbf.append("<img src="+image_links+">");
		    }

		    StringBuffer sbf3 = new StringBuffer();
		    sbf3.append(MyHtml.folderDisplay(fnames, vopt, 800, 400, cbf, "center", "default"));
		    StringBuffer sbf = new StringBuffer();
		    sbf.append(sbf1);
		    sbf.append(sbf2);
		    sbf.append(sbf3);
		    out.println(MyHtml.forumDisplay(sid, ad_left, sbf, ad_right));
		}
		*/
		out.println("</BODY></HTML>");
		return;
	    }
	    
	    /*
	    if(action != null && action.equals("delete_page")) {
		if(user_level != null && Integer.parseInt(user_level) >= 800000001) {
		    String fid = request.getParameter("file_id");
		    if(fid != null) {
			db.delete("DELETE FROM "+table_name+" WHERE FIELD1='"+fid+"';");
		    }
		}
	    }
	    */
	    /*
	    if(action.equals("2-1")) {
		String wid = "WWWC-"+ejbdb.getRowCounter("PRODUCTS");

		StringBuffer input_sbf = new StringBuffer();
		input_sbf.append("<input type=hidden name=sid value="+sid+">");
		input_sbf.append("<input type=hidden name=cname value="+cname+">");
		input_sbf.append("<input type=hidden name=sub_dir value="+sub_dir+">");
		input_sbf.append("<input type=hidden name=aid value=add_product_preview>");

		String name  = null;
		String value = null;

		StringBuffer sbf =  new StringBuffer();
		int t_specs = 0;
		int t_acces = 0;
		int t_img_l = 0;
		int t_img_a = 0;

		Hashtable tai_hash = new Hashtable();

		if(action != null && action.startsWith("add_")) {
		    Enumeration enum = request.getParameterNames();
		    while(enum.hasMoreElements()) {
			name  = (String)enum.nextElement();
			value = request.getParameter(name);
			if(value != null && (value.trim()).length()>0) {
			    // out.println("<BR>"+name+"="+value);
			    if(name.startsWith("spec_")) {
				t_specs++;
			    }
			    if(name.startsWith("accessory_")) {
				t_acces++;
			    }
			    if(name.startsWith("image_link")) {
				t_img_l++;
			    }
			    if(name.startsWith("image_attach")) {
				t_img_a++;
			    }
			    if(value.indexOf(34) != -1) {
				value = value.replaceAll("\"","\\\\\"");
			    }

			    sbf.append("if(document.postform."+name+" != null) {\n");
			    sbf.append("  document.postform."+name+".value=\""+value+"\";\n");
			    sbf.append("}\n");

			    if(name.startsWith("image_link_value_") && value.length()>6) {
				sbf.append("document."+name.substring(6)+".src=\""+value+"\";\n");
			    }
			    if(name.startsWith("image_attach_value_") && value.length()>6) {
				sbf.append("document."+name.substring(6)+".src=\""+value+"\";\n");
				tai_hash.put(name, value);
			    }
			}
		    }
		}
		out.println(tai_hash);
		ProductForms pf = new ProductForms();
		pf.setInput(input_sbf);
		pf.setScript(sbf);
		out.println(pf.getNewProductForm("Title:Add New Product","MainBarServlet",
						 "12345", t_specs, t_acces, t_img_l, t_img_a, tai_hash));
		out.println("</BODY></HTML>");
		return;
	    }
	    */
	    /*
	    if(action != null && action.equals("add_product_preview")) {
		
		String d_opt = request.getParameter("d_opt");

		out.println(MyJavaScript.getImageOnError("ImageError"));

		if(d_opt==null) {
		    out.println("<TABLE cellSpacing=0 cellPadding=0 border=0 width=900>");
		    out.println("<TR><TD width=600>");
		    out.println("<FORM name=sform action=ShoppingServlet  method=post>");
		    out.println("<TABLE cellSpacing=0 cellPadding=10 border=1 width=600>");
		    out.println("<TR><TD>Product:</TD><TD colspan=2><B>"+request.getParameter("product_name")+"</B></TD></TR>");
		    out.println("<TR><TD>Manufacture:</TD>");
		    out.println("<TD>"+request.getParameter("manufacture")+"</TD>");
		    out.println("<TD rowspan=3><img src='"+request.getParameter("image")+"' onError=ImageError(this);></TD></TR>");
		    out.println("<TR><TD>Manufacture-ID:</TD><TD>"+request.getParameter("manufacture_id")+"</TD></TR>");
		    out.println("<TR><TD>Made In:</TD><TD>"+request.getParameter("made_in")+"</TD></TR>");
		    out.println("</TABLE>");

		    out.println("<TABLE cellSpacing=0 cellPadding=10 border=1 width=600>");
		    out.println("<TR><TD>Overview:</TD><TD>"+request.getParameter("overview")+"</TD></TR>");
		    out.println("</TABLE>");

		    out.println("<TABLE cellSpacing=0 cellPadding=10 border=1 width=600>");
		    out.println("<TR><TD>Specifications:</TD>");
		    out.println("<TD>"+request.getParameter("spec_value")+"</TD></TR>");
		    out.println("</TABLE>");

		    out.println("<TABLE cellSpacing=0 cellPadding=10 border=1 width=600>");
		    out.println("<TR><TD>Features:</TD>");
		    out.println("<TD>");
		    out.println("<LI>"+request.getParameter("feature_name_0")+"</LI>");
		    out.println("<LI>"+request.getParameter("feature_name_0")+"</LI>");
		    out.println("</TD></TR>");
		    out.println("</TABLE>");

		    out.println("<TABLE cellSpacing=0 cellPadding=10 border=1 width=600>");
		    out.println("<TR><TD>Accessories(Inclued):</TD>");
		    out.println("<TD>"+request.getParameter("accessory_value_0")+"</TD></TR>");
		    out.println("</TABLE>");

		    out.println("<TABLE cellSpacing=0 cellPadding=10 border=1 width=600>");
		    out.println("<TR><TD>"+request.getParameter("image_link_name_0")+"</TD>");
		    out.println("<TD><img src='"+request.getParameter("image_link_value_0")+"' onError=ImageError(this);></TD></TR>");
		    out.println("<TR><TD>"+request.getParameter("image_attach_name_0")+"</TD>");
		    out.println("<TD><img src='"+request.getParameter("image_attach_value_0")+"' onError=ImageError(this);></TD></TR>");
		    out.println("<TR><TD>3WCenter ID</TD><TD>"+request.getParameter("wwwc_p_id")+"</TD></TR>");
		    out.println("</TABLE>");
		    
		    out.println("</TD><TD align=right valign=top width=200>");

		    out.println("<TABLE cellSpacing=0 cellPadding=10 border=1 width=200>");
		    out.println("<TR><TD>Accessories(Optional):</TD></TR>");
		    out.println("<TD>"+request.getParameter("accessory_value_0")+"</TD></TR>");
		    out.println("<TD>"+request.getParameter("accessory_value_0")+"</TD></TR>");
		    out.println("<TD>"+request.getParameter("accessory_value_0")+"</TD></TR>");
		    out.println("<TD>"+request.getParameter("accessory_value_0")+"</TD></TR>");
		    out.println("</TABLE>");
		    
		    out.println("</TD></TR>");
		    out.println("</TABLE>");
		}
		out.println("</BODY></HTML>");
		return;
	    }
	    */
	   

		/*
		int row_counter = ejbdb.getRowCounter(table_name);
		if(row_counter == -1) {
		    out.println(MyMessage.htmlMessage("Sorry. Please try again!"));
		    return;
		}

		String page = request.getParameter("page");
 
		if(page == null) {
		    page = "1";
		}

		query = "SELECT LIMIT "+(Integer.parseInt(page)-1)*Integer.parseInt(max_rows)+" "+
		    max_rows+" * FROM "+table_name +" ORDER BY FIELD2 DESC, FIELD3, FIELD1 DESC;";

		ArrayList alist = ejbdb.select(query);

		String page_id  = null;
		db.select("SELECT * FROM "+table_name+" WHERE FIELD28='"+page_id+"' ORDER BY FIELD1 DESC;");

		Vector v_r = new Vector();
		v_r = db.getTableRecordVector();

		if(v_r.size()==0) {
		out.println(MyMessage.htmlMessage("[<A href=PostPreference?sub_dir="+sub_dir+">Add</A>]"));
		return;
		}
	    
		out.println("<HTML><HEAD>");
		out.println("<TITLE>"+sub_dir+"</TITLE>");
		out.println("</HEAD><BODY><CENTER>");

		FieldRecord30 record = new FieldRecord30();
		Vector v = new Vector();
		String file_id  = null;
		String date     = null;
		String title    = null;
		String text1    = null;
		String image1   = null;

		int m = 0;
		Enumeration enum = v_r.elements();
		while (enum.hasMoreElements()) {
		v        = (Vector)enum.nextElement();
		record   = new FieldRecord30(v);
		file_id  = record.getField1();
		date     = record.getField7();
		title    = record.getField9();
		text1    = record.getField10();
		image1   = record.getField13();

		out.println("<TABLE border=0 width=90%>");
		out.println("<TR><TD align=left><HR width=90% height=2></TD></TR>");

		if(user_level != null && Integer.parseInt(user_level) >= 800000001) {
		    out.println("<TR><TD align=left>");
		    out.println("<B>[<A href=ShoppingDisplayServlet?action=delete_page&sub_dir="+sub_dir+"&file_id="+file_id+">");
		    out.println("Delete</A>]["+date+"]</B>&nbsp;&nbsp;");
		}
		else {
		    out.println("<TR><TD align=left><B>["+date+"]&nbsp;&nbsp");
		}
		out.println("<A href=ShoppingDisplayServlet?action=open_page&sub_dir="+sub_dir+
			    "&file_id="+file_id+" target=_blank>"+
			    title+"</A></B></TD></TR>");	

		out.println("<TR><TD>");

		out.println("<TABLE border=0>");

		if(image1==null || image1.length()<10) {
		    out.println("<TR><TD align=left valign=top>");
		    out.println("<A href=ShoppingDisplayServlet?action=open_page&sub_dir="+sub_dir+
				"&file_id="+file_id+" target=_blank>");
		    out.println("<IMG src=/index/images/apps/no_image.gif border=0></A></TD>");
		}
		else {
		    
		    int sw = image1.indexOf("width=");
		    int sh = image1.indexOf("height=");
		    if(sw != -1 && sh != -1) {
			String w = image1.substring(sw+6, sh-1);
			String h = image1.substring(sh+7);
			if(h.indexOf(">") != -1) {
			    h = h.replaceAll(">","");
			}

			String format ="0123456789.";
			if(UserInputCheck.checkFormat(w,format) && UserInputCheck.checkFormat(h,format)) { 
			    int p = w.indexOf(".");
			    if(p != -1) {
				w = w.substring(0,p);
			    }

			    int q = h.indexOf(".");
			    if(q != -1) {
				h = h.substring(0,q);
			    }

			    int width = Integer.parseInt(w);
			    int height= Integer.parseInt(h);
			    while(width>100 || height>150) {
				width = width - width/100;
				height = height - height/100;
			    }
			    image1 = image1.substring(0,sw);
			    image1 = image1 +" width="+width +" height="+height+" border=0>";
			}
		    }

		    out.println("<TR><TD align=left valign=top>");
		    
		    out.println("<TABLE border=0 width=100 height=150 style=\"border: 1 solid #FFFFFF\">");
		    out.println("<TR><TD align=center valign=top style=\"background-color: #FFFFFF\">");
		    out.println("<A href=ShoppingDisplayServlet?action=open_page&sub_dir="+
				sub_dir+"&file_id="+file_id+" target=_blank>"+image1+"</A>");
		    out.println("</TD></TR></TABLE></TD>");
		}
		
		out.println("<TD>&nbsp</TD>");
		out.println("<TD align=left valign=top>"+text1+"</TD></TR>");	
		out.println("</TABLE>");


		out.println("</TD></TR>");
		out.println("</TABLE>");

		max_page = record.getField29();
		if(max_page == null || max_page.length()==0) {
		    max_page = "1";
		    }
		m++;
		}
	   
		out.println("<TABLE align=center border=0 width=90%>");  
		out.println("<TR><TD align=left><HR width=90% height=2></TD></TR>");
		out.println("</TABLE>");  
		out.println("<TABLE style='font-size: 10pt' align=center>");  
		out.println("<TR><TD><B>[<A href=PostPreference?sub_dir="+sub_dir+">Add</A>]</B></TD>");
		int cp = Integer.parseInt(page_id);
		int tp = Integer.parseInt(max_page);
		
		for(int j=1; j<= tp; j++) {
		if(j==cp) {
		    out.println("<TD><B>["+j+"]</B></TD>");
		}
		else {
		    out.print("<TD><B>[<A href=ForumDisplayServlet?sub_dir="+sub_dir+"&page_id="+j+">"+j+"</A>]</B></TD>");
		}
		if(j==26 && j < tp) {
		    break;
		    }
		    }
	    
		    if(tp>26) {
		    out.println("<FORM name=more_page method=post action=ShoppingDisplayServlet>");
		    out.println("<input type=hidden name=sub_dir value="+sub_dir+">");
		    out.println("<TD valign=top align=left style='font-size: 8pt'>");
		    out.println("<SELECT name=page_id onChange=document.forms.more_page.submit();>");
		    for(int j=27; j<=tp; j++) {
		    if(page_id.equals(j+"")) {
		    out.println("<OPTION value="+j+" selected>"+j+"</OPTION>");
		    }
		    else {
			out.println("<OPTION value="+j+">"+j+"</OPTION>");
		    }
		}
		out.println("<SELECT></TD>");
		out.println("<input type=hidden name=max_page value="+max_page+">");
		out.println("</FORM>");
	    }

	    out.println("</TR>");
	    out.println("</TABLE>");

	    out.println("</CENTER></BODY></HTML>");
	    return;
		*/
	}
	catch(IOException e) {

	}
    }
}
